﻿using DevExpress.CodeParser;
using FuelDXApplication1.Entity;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using static FuelDXApplication1.Dto.Remote;

namespace FuelDXApplication1.MksWinform
{
    public partial class RemoteQuery : Form
    {
        private int pageIndex = 1;
        private int pageSize = 2;
        int pageCount;
        int TotalCount;

        public RemoteQuery()
        {
            InitializeComponent();
        }

        private async void RemoteQuery_Load(object sender, EventArgs e)
        {
            Pagheind();
        }

        private async void Pagheind() 
        {
            PageGetBase asds = new(pageIndex, pageSize);

            var basinfolis = await HttpClientHelper.RequestUrl<PageGetBase, PageInfoSHow<List<RemoteDatum>>>("https://localhost:44341/", $"api/app/fuel-synchronization/base?pageIndex={pageIndex}&pageSize={pageSize}", MethodType.Get, asds);
            gridControl1.DataSource = basinfolis.Data;

            //计算总页数
            pageCount = basinfolis.pageCount;
            TotalCount = basinfolis.totalCount;
        }

        /// <summary>
        /// 首页
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void simpleButton1_Click(object sender, EventArgs e)
        {
            pageIndex = 1;
            Pagheind();
        }

        /// <summary>
        /// 上一页
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void simpleButton2_Click(object sender, EventArgs e)
        {
            if (pageIndex > 1)
            {
                pageIndex--;
                Pagheind();
            }
        }
        /// <summary>
        /// 下一页
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void simpleButton3_Click(object sender, EventArgs e)
        {
            if (pageIndex < pageCount)
            {
                pageIndex++;
                Pagheind();
            }
        }

        /// <summary>
        /// 尾页
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void simpleButton4_Click(object sender, EventArgs e)
        {
            pageIndex = pageCount;
            Pagheind();
        }

        public record PageGetBase(int pageIndex, int pageSize);





    }
}
